package io;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * jdk1.7通过try-catch-resource简化了输入输出流的关闭操作
 */
public class TryWithResource {
    public static void main(String[] args) {
        try (
                FileInputStream fis = new FileInputStream("G:\\test.txt");
                BufferedInputStream bis = new BufferedInputStream(fis);
                FileOutputStream fos = new FileOutputStream("G:\\copy.txt");
                BufferedOutputStream bos = new BufferedOutputStream(fos);
            )
        {
            int size;
            byte[] buf = new byte[1024];
            while ((size = bis.read(buf)) != -1) {
                bos.write(buf, 0, size);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
